var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showModal: false,
    head: "../../res/ddywc_banner.png",
    array: ['是', '否'],
    index:0,
    name:'',
    head:'',
    heads:'',
    desc:'',
    price:0,
    zj_price:0,
    line_price:0,
    sales:0,
    ct_num:0
  },


  onLoad: function (options) {
    var pt_id = options.id;
    this.setData({
      pt_id:pt_id
    })
    this.getStoredInfo();
  },

  getStoredInfo:function(){
    var t = this;
    app.visit("huodong/getStorePinTuanInfo", {
      pt_id:t.data.pt_id,
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        t.setData({
          info:c.data,
          name:c.data.name,
          pt_id:c.data.id,
          head:c.data.imgs,
          heads:c.data.imgs2,
          desc:c.data.desc,
          price:c.data.price,
          zj_price:c.data.zj_price,
          line_price:c.data.line_price,
          sales:c.data.sales,
          ct_num:c.data.ct_num,
          index:c.data.is_shangjia == 2 ? 0 : 1
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  tijiao:function(e){
    var t = this;
    app.visit("huodong/setStorePinTuanInfo", {
      pt_id:t.data.pt_id,
      name:t.data.name,
      heads:t.data.heads,
      desc:t.data.desc,
      price:t.data.price,
      zj_price:t.data.zj_price,
      line_price:t.data.line_price,
      sales:t.data.sales,
      ct_num:t.data.ct_num,
      index:t.data.index
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        wx.showToast({
          title: '修改成功',
          icon: 'none',
          success: function () {
            wx.navigateBack();
          }
        })
      }else{
        app.showToast(c.msg)
      }
    })
  },

  setCtnum:function(e){
    this.setData({
      ct_num:e.detail.value
    })
  },

  setSales:function(e){
    this.setData({
      sales:e.detail.value
    })
  },

  setLineprice:function(e){
    this.setData({
      line_price:e.detail.value
    })
  },

  setZjprice:function(e){
    this.setData({
      zj_price:e.detail.value
    })
  },

  setPrice:function(e){
    this.setData({
      price:e.detail.value
    })
  },

  setName:function(e){
    this.setData({
      name:e.detail.value
    })
  },

  setDesc:function(e){
    this.setData({
      desc:e.detail.value
    })
  },

  bindPickerChange: function (e) {
    console.log(e.detail.value)
    this.setData({
      index: e.detail.value
    })
  },
  headimage: function () {

    var _this = this;
    wx.chooseImage({
      count: 1, // 默认9     
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: function (res) {
        console.log(res)
        wx.uploadFile({
          url: app.api_url + "/api/index/ups",
          filePath: res.tempFilePaths[0],
          name: "file",
          header: {
            Authorization: wx.getStorageSync("user_id"),
            "Content-Type": "application/x-www-form-urlencoded"
          },
          success: function(e) {
            console.error("上传回执", e);
            var a;
            0 == (a = "string" == typeof e.data ? JSON.parse(e.data) : e.data).code ? _this.setData({
              head: a.data.url,
              heads: a.data.img
            }) : wx.showToast({
              title: "上传失败"
            });
          },
          complete: function() {}
        });
      }
    })
  },

})